import { request } from "@/utils/service"
import type * as User from "./types/user"

/** 增/改 */
export function saveUserDataApi(data: User.CreateOrUpdateUserRequestData) {
  debugger
  return request({
    url: "user/save",
    method: "post",
    data
  })
}

/** 删 */
export function deleteUserDataApi(id: number) {
  return request({
    url: `user/${id}`,
    method: "post"
  })
}

/** 查 */
export function getUserDataApi(data: User.UserRequestData) {
  return request<User.UserResponseData>({
    url: "user/list",
    method: "post",
    data: data
  })
}

export function updateEnablApi(id: number, enable: boolean) {
  return request({
    url: `user/updateStatus/${id}/${enable}`,
    method: "get"
  })
}

export function updateGroupApi(id: number, groupId: number, assignee: string) {
  return request<ApiResponseData<User.UserData>>({
    url: `user/updateGroup/${id}/${groupId}`,
    method: "get",
    params: {
      assignee
    }
  })
}

/** 更新当前登录人的密码 */
export function updatePasswordApi(id: number, password: string) {
  return request({
    url: `user/updatePassword`,
    method: "post",
    params: {
      id,
      password
    }
  })
}
